home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-23 | 5.9 KB | 206 lines | [TEXT/ALFA] |
- \
- \
- \ PF Forms Handler: Fields -- version 1.3.2
- \
- \
- \ (c) Ronald T. Kneusel, 1995, 1996
- \ (rkneusel@post.its.mcw.edu)
- \
- \ This code may be used and distributed freely provided the copyright
- \ notice remains intact and my name is mentioned in the documentation.
- \
- \ Last mod: 23-Apr-96
- \ =========================================================================
- \
- \ These are the new field definition words.
- \
- \ It assumes these files to be already loaded:
- \
- \ server.4th - web server interface
- \ string.4th - string words
- \
- \
- \ Field record:
- \
- \ +----+--------+-----------+---------------+
- \ |type| name | value ... | text ........ |
- \ +----+--------+-----------+---------------+
- \
- \ where:
- \
- \ type (1 byte) = 0 STR, 1 INT, 5 FP
- \ name (30 bytes) = null terminated text of field name
- \ value (0,2,10 bytes) = value of field, for STR is same as start of text,
- \ 2 bytes for INT, 10 bytes for FP
- \ text (varies) = text string of value, i.e. INT is 2 then text is "2"
- \
- \
- \ Object:
- \
- \ Identical to field record but not entered in field array.
- \
-
- \ *** None of these words check for overflow or error conditions! Memory is
- \ at a premium, so you, the programmer, are on your own!
-
-
- \ Misc support words
-
- : notvalid? ( c -- t|f ) \ true if c not a valid number character
- dup 45 = IF drop 0 exit THEN \ is it '-'?
- dup 46 = IF drop 0 exit THEN \ '.'
- dup 43 = IF drop 0 exit THEN \ '+'
- dup 69 = IF drop 0 exit THEN \ 'E'
- dup 101 = IF drop 0 exit THEN \ 'e'
- dup 47 > swap 58 < and IF 0 exit THEN \ '0' through '9'
- -1 \ something else
- ;
-
- : ok? ( s -- s t|f ) \ true if string a valid number
- dup c@ 0= IF 0
- ELSE \ not null
- dup dup dup length + swap
- DO
- r c@ notvalid? IF
- 0 10000 ELSE 1 THEN
- +LOOP dup 0= IF ( 0 ) ELSE -1 THEN
- THEN
- ;
-
- variable #digits \ holds number of significant digits
- 6 #digits ! \ default to 6 digits
- : f< ( f1 f2 -- f1<f2 ) fcompare >r fdrop fdrop r> -1 = ;
- : f> ( f1 f2 -- f1>f2 ) fcompare >r fdrop fdrop r> 1 = ;
- : pp ( f -- f ) \ set the output number format
- fdup fabs fdup
- 0.009 f> >r 100000.0 f< r> and
- IF #digits @ fix ELSE #digits @ sci THEN ;
-
-
- \ Data types
-
- 0 constant STR \ string
- 1 constant INT \ integer
- 5 constant FP \ floating point
-
- \ Record access
-
- : .type ( r -- t ) c@ ; \ return data type
- : .name ( r -- a ) 1+ ; \ return address of field name
-
- : .val ( r -- a ) 31 + ; \ return *address* of value
-
- : @val ( r -- v ) \ return *value* of field, addr if STR
- dup >r .val r> c@
- dup STR = IF drop ELSE \ STR
- dup INT = IF drop @ ELSE \ INT
- dup FP = IF drop f@ ELSE \ FP
- drop drop 0 THEN THEN THEN \ error
- ;
-
-
- : $%int ( r+31 -- ) \ take int value and put in text area as a string
- dup 2+ >r @ 0 d>f 0 fix r> f>str ;
-
- : $%fp ( r+31 -- ) \ take fp value and put in text area as a string
- dup 10 + >r f@ pp r> f>str ;
-
- : !val ( v r -- ) \ put the value, by type, in the record
- dup >r .val r> c@
- dup STR = IF drop dup 0 swap c! strcpy ELSE \ STR, copy string
- dup INT = IF drop dup >r ! r> $%int ELSE \ INT
- dup FP = IF drop dup >r f! r> $%fp ELSE \ FP
- drop drop THEN THEN THEN \ error
- ;
-
- : .text ( r -- a ) \ return the *address* of the field text
- dup c@
- dup STR = IF drop 31 + ELSE \ STR
- dup INT = IF drop 33 + ELSE \ INT
- dup FP = IF drop 41 + ELSE \ FP
- drop drop 0 THEN THEN THEN \ error
- ;
-
-
- \ Template and Field array words
-
- create (T) 50 2* allot \ template array
- create (F) 50 2* allot \ field array
-
- variable #T# 0 #T# ! \ template array index
- variable #F# 0 #F# ! \ field array index
-
- : >table ( r_addr -- ) \ enter record in the table
- #T# @ 2* (T) + ! #T# @ 1+ #T# ! ;
-
- : >field ( r_addr -- ) \ enter record in the field array
- #F# @ 2* (F) + ! #F# @ 1+ #F# ! ;
-
- : @(T) ( idx -- addr ) 2* (T) + @ ;
- : @(F) ( idx -- addr ) 2* (F) + @ ;
-
-
- \ Define a field record
-
- 30 $variable @#$
- : " ( string -- ) \ assign text to a string from the input stream.
- @#$ 34 word here >null here swap $copy ;
-
- : #FIELD \ define a field record
- CREATE here >r swap dup >r 2* + 31 + allot
- ( compiling: type text-size -- addr )
- r> ( type) r> ( addr)
- 2dup c! ( set type )
- swap drop dup >r 1+ @#$ swap strcpy ( set name)
- r >table ( enter in template array)
- r> >field ; ( enter in fields array)
- ( runtime: -- addr )
-
-
- \
- \ E.g. A floating point field 15 characters long named HEIGHT is defined as:
- \
- \ FP 15 " height" #FIELD height
- \
-
- : #OBJECT \ define an object
- CREATE here >r swap dup >r 2* + 31 + allot
- ( compiling: type text-size -- addr )
- r> ( type) r> ( addr)
- 2dup c! ( set type )
- swap drop dup >r 1+ @#$ swap strcpy ( set name)
- r> >table ; ( enter in template array)
- ( runtime: -- addr )
-
- \
- \ E.g. A floating point object 15 characters long named WIDTH is defined as:
- \
- \ FP 15 " width" #OBJECT width
- \
-
-
-
- \ Initialize the fields
-
- : <<int ( idx -- ) \ put the integer string in the integer part
- @(F) dup 33 + ok? IF str>f f>d drop ELSE 0 THEN swap 31 + ! ;
-
- : <<fp ( idx -- ) \ put the float string in the float part
- @(F) dup >r 41 + ok? IF str>f ELSE 0.0 THEN r> 31 + f! ;
-
- : <getFields> ( -- ) \ get the fields from the Apple Event and initialize
- #F# @ 0 DO \ for each field
- r @(F) 1+ \ get the name
- r @(F) .text swap NEW \ and the target
- @Field \ fill in the initial string value
- r @(F) c@ \ get the type
- dup 0= IF drop ELSE \ STR, nothing to do
- dup 1 = IF drop r <<int ELSE \ INT, get integer from string
- dup 5 = IF drop r <<fp ELSE \ FP, get float from string
- drop THEN THEN THEN
- LOOP \ move to the next field
- ;
-
-
- \ on to template.4th...
-